package com.boarsoft.boar.demo.user;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.boarsoft.boar.demo.user.entity.PocUser;
import com.boarsoft.boar.demo.user.service.PocAccountService;
import com.boarsoft.boar.demo.user.service.PocUserService;

public class UserTestMain {
	private static final String dateFormate = "yyyy-MM-dd";
	private static ClassPathXmlApplicationContext ctx;

	public static void main(String[] args) {
		ctx = new ClassPathXmlApplicationContext("classpath:conf/context.xml");
		System.out.println("Startup ".concat(ctx.isRunning() ? "successfully." : "failed."));

		/*
		 * accountTransferTest(ctx); accountReverseTest(ctx);
		 */
		userListTest(ctx);
	}

	public static void userListTest(ClassPathXmlApplicationContext ctx) {

		PocUserService pocUserService = ctx.getBean(PocUserService.class);

		PocUser pocUser = pocUserService.find(12344, 666666);
		System.out.println("用户信息：" + pocUser);
		pocUser = pocUserService.find(12345, 666666);
		System.out.println("用户信息：" + pocUser);
	}

	public static void accountTransferTest(ClassPathXmlApplicationContext ctx) {

		PocAccountService pocAccountService = ctx.getBean(PocAccountService.class);

		boolean flag = pocAccountService.accountTransfer("0110101232301000010001", "106130121012348108",
				new BigDecimal("999.88"));
		if (flag == true) {
			System.out.println("转账成功");
		} else {
			System.out.println("转账失败");
		}
	}

	public static void accountReverseTest(ClassPathXmlApplicationContext ctx) {

		PocAccountService pocAccountService = ctx.getBean(PocAccountService.class);

		boolean flag = pocAccountService.accountReverse("0040828076", new SimpleDateFormat(dateFormate).format(new Date()));
		if (flag == true) {
			System.out.println("冲正成功");
		} else {
			System.out.println("冲正失败");
		}
	}
}
